const hello = (name: string) => console.log(`hello, my name is ${name}`)

hello('tom')

const str: string = 'tom';
const num: number = Infinity;
const bool: boolean = false;
const arr: string[] = ['aaa'];
const arr1: Array<string> = ['aaa'];
const arr2: [string] = ['aaa'];
const arr3: [string, number] = ['aaa', 123];
const emtpy: null = null;
const a: void = undefined;
const b: undefined = undefined;
const c: symbol = Symbol()
const obj: {name: string} = {name: 'tom'};

//  枚举
const enum postStatus{
    aaa,
    bbb,
    ccc
}
const post = {
    type: postStatus.aaa
}

//  函数类型
function fn1(name: string) {
    return name
}

const fn2: (name: string) => string = name => name;

//  任意类型
function stringfy(string: any) {
    return JSON.stringify(string)
}

//  类型断言
const arr4 = [100, 200, 300, 400];
const res = arr4.find(num => num > 200) as number
const num1 = res as number;
const sum = 100 + res;
const sum1 = 100 + num1;

//  接口
interface postType {
    title: string
    content: string
    subTitle?: string
    readonly summary: string
}
interface anyType {
    [key: string]: string
}
const printPost = (post: postType) => {
    console.log(post.title)
    console.log(post.content)
}

// 类
interface talkType {
    talk (str: string): void
}
interface eatType {
    eat(food: string): void
}
class Person implements talkType, eatType {
    public name: string;
    public age: number;
    private readonly height: number;
    constructor(name: string, age: number, height: number) {
        this.name = name;
        this.age = age;
        this.height = height;
    }

    getHeight() {
        return this.height;
    }
    talk(str: string) {
        console.log(str)
    }
    eat(str: string) {
        console.log(str)
    }
}

// 泛型

function createArray<T> (length: number, value: T) {
    const arr = Array(length).fill(value) as T[]
    return arr
}
